﻿@{
    ViewBag.Title = this.Context.Request.QueryString["title"];
    Layout = "~/Views/Shared/_PageLayout.cshtml";
}

@section scripts
{
    @Scripts.Render("~/Scripts/swfupload")
    <script type="text/javascript">

        //挂接ExtJS准备完毕事件
        Ext.onReady
        (function () {
            //初始化快速提示
            Ext.QuickTips.init();

            //设置状态保存提供者（当前设置为Cookie）
            Ext.state.Manager.setProvider(Ext.create('Ext.state.CookieProvider', { path: _StatePath }));

            //用于记录当前记录
            var _CurrentRecord = undefined;

            //用于记录当前文件记录
            var _CurrentFile = undefined;

            //用于记录当前文件图片集合
            var _CurrentFileImages = [];


            //编辑界面
            var _CurrentFace = undefined;

            
            //创建数据存储对象
            var store = Ext.create
            (
                'Ext.data.Store',
                {
                    pageSize: 20,
                    autoSync: false,
                    autoLoad: false,
                    root: 'data',
                    remoteFilter: true,
                    remoteSort: true,
                    sorters: [{ property: 'Operation_ID', direction: 'ASC' }],
                    model: 'ActiveOperations',
                    listeners:
                    {
                        //处理数据加载事件
                        load: function (store, records, successful, eOpts) {
                            //获得当前选中行
                            var models = grid.getSelectionModel().getSelection();

                            //判断是否选中数据
                            if (models.length > 0) {
                                //设置当前选中记录
                                _CurrentRecord = store.getById(models[0].getId());
                            }
                            else {
                                //设置当前选中记录
                                _CurrentRecord = null;
                            }
                            //更新按钮状态
                            UpdateButtonState(_CurrentRecord);
                        }
                    },
                    proxy:
                    {
                        type: 'ajax',
                        batchActions: false,
                        url: spms.url.Action('List', 'ActiveOperation'),
                        reader:
                        {
                            type: 'json',
                            root: 'data'
                        },
                        listeners:
                        {
                            //处理代理异常
                            exception: spms.exception.HandleProxyError
                        }
                    }
                }
            );
            
            //创建工具栏
            var toolbar = Ext.create
            (
                'Ext.toolbar.Toolbar',
                {
                    region: 'north',
                    layout: 'hbox',
                    border: 5,
                    height: 32,
                    border: '1 0 1 0',
                    margins: '0 0 0 0',
                    padding: '0 6 0 6',
                    items:
                    [
                        {
                            id: 'spms-cmd-refresh',
                            text: '刷新',
                            tooltip: '重新加载数据',
                            tooltipType: 'qtip',
                            iconCls: 'spms-icon-refresh',
                            cls: 'spms-page-menu-button',
                            listeners:
                            {
                                click: OnRefresh
                            }
                        },
                        '-',
                        {
                            id: 'spms-cmd-add',
                            text: '新增',
                            tooltip: '新增作业',
                            tooltipType: 'qtip',
                            cls: 'spms-page-menu-button',
                            iconCls: 'spms-icon-add',
                            listeners:
                            {
                                click: OnAdd
                            }
                        },
                        {
                            id: 'spms-cmd-remove',
                            text: '删除',
                            tooltip: '删除选中的作业',
                            tooltipType: 'qtip',
                            cls: 'spms-page-menu-button',
                            iconCls: 'spms-icon-delete',
                            disabled: true,
                            listeners:
                            {
                                click: OnRemove
                            }
                        },
                        {
                            id: 'spms-cmd-edit',
                            text: '编辑',
                            tooltip: '编辑选中的作业',
                            tooltipType: 'qtip',
                            cls: 'spms-page-menu-button',
                            iconCls: 'spms-icon-edit',
                            disabled: true,
                            listeners:
                            {
                                click: OnEdit
                            }
                        }
                    ]
                }
            );

            //创建检索面板
            var search = Ext.create
            (
                'Ext.panel.Panel',
                {
                    region: 'north',
                    frame: false,
                    animCollapse: false,
                    iconCls: 'spms-icon-search',
                    stateful: true,
                    stateId: 'spms-account-search-state',
                    collapsible: true,
                    collapseMode: 'header',
                    titleCollapse: true,
                    collapsed: true,
                    margin: '0 0 6 0',
                    layout: 'fit',
                    id: 'spms-panel-search',
                    cls: 'spms-page-card-detail',
                    border: true,
                    title: '检索',
                    listeners:
                    {
                        //挂接显示事件
                        show: function (win, options) {
                            //获得表单
                            var form = win.down('form');

                            //判断是否存在
                            if (form) {
                                //重置内容
                                form.getForm().reset();

                                //设置焦点
                                form.down('field').focus(false, 50);
                            }
                        }
                    },
                    items:
                    [
                        {
                            xtype: 'form',
                            frame: false,
                            autoScroll: true,
                            bodyPadding: 6,
                            bodyCls: 'spms-page-card-detail-form-body',
                            bodyBorder: false,
                            border: false,
                            layout:
                            {
                                type: 'table',
                                columns: 2,
                                tableAttrs:
                                {
                                    style:
                                    {
                                        width: '100%'
                                    },
                                    cellpadding: 6
                                }
                            },
                            items:
                            [
                                {
                                    xtype: 'fieldcontainer',
                                    width: '100%',
                                    defaultType: 'textfield',
                                    layout:
                                    {
                                        type: 'hbox',
                                        align: 'stretch'
                                    },
                                    padding: 0,
                                    border: 0,
                                    items:
                                    [
                                        {
                                            fieldLabel: '',
                                            minWidth: 80,
                                            maxLength: 20,
                                            xtype: 'checkbox',
                                            boxLabel: '编号:',
                                            cls: 'spms-card-checkbox',
                                            boxLabelCls: 'spms-card-checkbox-boxlabel',
                                            itemId: 'chkOperation_Code',
                                            allowBlank: true,
                                            value: true,
                                            inputValue: true,
                                            listeners:
                                            {
                                                change: spms.event.OnCheckBoxLabelChange
                                            }
                                        },
                                        {
                                            fieldLabel: '',
                                            itemId: 'Operation_Code',
                                            flex: 1
                                        }
                                    ]
                                },
                                {
                                    xtype: 'fieldcontainer',
                                    width: '100%',
                                    defaultType: 'textfield',
                                    layout:
                                    {
                                        type: 'hbox',
                                        align: 'stretch'
                                    },
                                    padding: 0,
                                    border: 0,
                                    items:
                                    [
                                        {
                                            fieldLabel: '',
                                            minWidth: 80,
                                            maxLength: 20,
                                            xtype: 'checkbox',
                                            boxLabel: '状态:',
                                            cls: 'spms-card-checkbox',
                                            boxLabelCls: 'spms-card-checkbox-boxlabel',
                                            itemId: 'chkStatus',
                                            allowBlank: true,
                                            value: true,
                                            inputValue: true,
                                            listeners:
                                            {
                                                change: spms.event.OnCheckBoxLabelChange
                                            }
                                        },
                                        {
                                            fieldLabel: '',
                                            itemId: 'Status',
                                            flex: 1
                                        }
                                    ]
                                }
                            ],
                            dockedItems:
                            [
                                {
                                    xtype: 'toolbar',
                                    dock: 'bottom',
                                    ui: 'footer',
                                    cls: 'spms-page-card-toolbar',
                                    padding: '0 6 12 0',
                                    items:
                                    [
                                        '->',
                                        {
                                            text: '检索',
                                            xtype: 'button',
                                            cls: 'spms-page-card-detail-toolbar-button',
                                            handler: function () {
                                                //获得当前对象
                                                var me = this;

                                                //获得表单对象
                                                var form = me.up('form');

                                                //检查数据是否合法
                                                if (form.getForm().isValid()) {
                                                    //清除过滤条件
                                                    store.filters.clear();

                                                    //生成过滤条件
                                                    var filters = new Array();

                                                    //判断是否以账户名检索
                                                    if (form.down('#chkOperation_Code').getValue()) {
                                                        //添加检索条件
                                                        filters.push({ property: 'Operation_Code@C', value: form.down('#Operation_Code').getValue() });
                                                    }

                                                    //判断是否以职员名检索
                                                    if (form.down('#chkStatus').getValue()) {
                                                        //添加检索条件
                                                        filters.push({ property: 'Status@C', value: form.down('#Status').getValue() });
                                                    }
                                                    //刷新数据
                                                    Refresh({ filters: filters });
                                                }
                                            }
                                        }
                                    ]
                                }
                            ]
                        }
                    ]
                }
            );

            //创建表格
            var grid = Ext.create
            (
                'Ext.grid.Panel',
                {
                    region: 'center',
                    store: store,
                    stateful: true,
                    border: true,
                    cls: 'spms-grid',
                    stateId: 'spms-account-grid-state',
                    id: 'spms-card-grid',
                    forceFit: true,
                    autoScroll: true,
                    columnLines: true,
                    enableLocking: true,
                    unlockText: spms.resources.text_grid_column_unlock,
                    lockText: spms.resources.text_grid_column_lock,
                    viewConfig:
                    {
                        stripeRows: true,
                        loadingText: spms.resources.text_loading,
                        singleSelect: true
                    },
                    bbar: Ext.create
                        (
                        'SPMS.PagingToolbar',
                        {
                            store: store
                        }
                    ),
                    listeners:
                    {
                        select: OnRowSelect
                    },
                    columns:
                    [
                        {
                            text: '编号',
                            width: 100,
                            minWidth: 120,
                            sortable: true,
                            align: 'left',
                            dataIndex: 'Operation_Code',
                            hideable: false,
                            lockable: true
                        },
                        {
                            text: '作业类型',
                            width: 60,
                            minWidth: 80,
                            sortable: true,
                            align: 'center',
                            dataIndex: 'OperationType_ID',
                            hideable: true
                        },
                        {
                            text: '企业名称',
                            width: 140,
                            minWidth: 80,
                            sortable: true,
                            align: 'center',
                            dataIndex: 'CompanyName',
                            hideable: true
                        },
                        {
                            text: '法人',
                            width: 80,
                            minWidth: 80,
                            sortable: true,
                            align: 'center',
                            dataIndex: 'ContactPerson',
                            hideable: true
                        },

                        {
                            text: '状态',
                            width: 80,
                            minWidth: 80,
                            sortable: true,
                            align: 'center',
                            dataIndex: 'Status',
                            hideable: true
                        },
                        {
                            text: '联系电话1',
                            width: 120,
                            minWidth: 120,
                            sortable: false,
                            align: 'left',
                            dataIndex: 'ContactNumber1',
                            hideable: true
                        },
                        {
                            text: '联系电话2',
                            width: 120,
                            minWidth: 120,
                            sortable: false,
                            align: 'left',
                            dataIndex: 'ContactEmail1',
                            hideable: true
                        },
                        {
                            text: '电子邮箱',
                            width: 240,
                            minWidth: 120,
                            sortable: false,
                            align: 'left',
                            dataIndex: 'ContactEmail',
                            hideable: true
                        },
                        {
                            text: '备注',
                            width: 140,
                            minWidth: 240,
                            sortable: false,
                            align: 'left',
                            dataIndex: 'Memo',
                            hideable: true,
                            flex: 1
                        }
                    ]
                }
            );

            //创建布局
            var card = Ext.create
            (
                'Ext.panel.Panel',
                {
                    region: 'center',
                    layout: 'card',
                    border: false,
                    defaults:
                    {
                        border: false
                    },
                    bodyStyle: 'padding:12px',
                    items:
                    [
                        {
                            xtype: 'panel',
                            id: 'spms-card-list',
                            layout: 'border',
                            items:
                            [
                                search,
                                grid
                            ]
                        }
                    ]
                }
            );

            //创建视口
            var viewport = Ext.create
            (
                'Ext.container.Viewport',
                {
                    layout: 'border',
                    items:
                    [
                        {
                            region: 'north',
                            contentEl: 'spms-page-title',
                            border: false,
                            height: 48,
                            margins: '0 0 0 0'
                        },
                        toolbar,
                        card
                    ]
                }
            );

            //加载数据
            store.load();

            //更新按钮状态

            function UpdateButtonState(record) {
                //判断是否选中记录
                if (record) {
                    //设置删除按钮状态
                    spms.common.SetDisabled('spms-cmd-remove', record.get('IsBuildin'));
                    //设置编辑按钮状态
                    spms.common.SetEnabled('spms-cmd-edit', true);
                   
                }
                else {
                    //设置删除按钮状态
                    spms.common.SetEnabled('spms-cmd-remove', false);
                    //设置编辑按钮状态
                    spms.common.SetEnabled('spms-cmd-edit', false);
                   
                }
            }

            //处理刷新按钮点击事件
            function OnRefresh(sender) {
                //刷新数据
                Refresh();
            }

            //处理新增按钮点击事件
            function OnAdd(sender) {
                //获得当前对象
                var me = this;

                //判断窗体是否已经初始化
                if (typeof me._Panel_Create == 'undefined') {
                   
                    //创建必要文件存储
                    me._FileFirstList = [];

                    //创建辅助文件存储              

                    me._FileSecondList = []; 
                    //创建新增面板
                    me._Panel_Create = Ext.create
                    (
                        'Ext.panel.Panel',
                        {
                            layout: 'border',
                            id: 'spms-card-create',
                            cls: 'spms-page-card-detail',
                            border: false,
                            header:
                            {
                                title: '新增作业',
                                border: false,
                                height: 36,
                                cls: 'spms-page-card-detail-header'
                            },
                            listeners:
                            {
                                //挂接显示事件
                                show: function (win, options) {
                                    //获得表单
                                    var form = win.down('form');

                                    //判断是否存在
                                    if (form) {
                                        //获得窗体
                                        form.getForm().reset();

                                        //设置焦点
                                        form.down('field').focus(false, 50);
                                    }
                                }
                            },
                            items:
                            [
                                {
                                    xtype: 'form',
                                    region: 'center',
                                    autoScroll: true,
                                    frame: false,
                                    method: 'POST',
                                    waitMsgTarget: true,
                                    waitTitle: spms.resources.text_app_title,
                                    bodyPadding: 12,
                                    bodyCls: 'spms-page-card-detail-form-body',
                                    bodyBorder: false,
                                    border: false,
                                    defaultType: 'textfield',
                                    fieldDefaults:
                                    {
                                        labelAlign: 'left',
                                        labelWidth: '10%',
                                        anchor: '100%',
                                        msgTarget: 'qtip'

                                    },
                                    items:
                                    [
                                        {
                                            xtype: 'textfield',
                                            width: '101%',
                                            name: 'CompanyName',
                                            maxLength: 40,
                                            minLength: 4,
                                            fieldLabel: '企业名称',
                                            emptyText: '企业名称',
                                            allowBlank: false,
                                            disabled: false
                                        },
                                        {
                                            xtype: 'textfield',
                                            name: 'ContactPerson',
                                            width: '60%',
                                            fieldLabel: '企业法人',
                                            emptyText: '企业法人',
                                            allowBlank: false,
                                            disabled: false
                                        },
                                        {
                                            xtype: 'fieldcontainer',
                                            width: '100%',
                                            defaultType: 'textfield',
                                            layout:
                                            {
                                                type: 'hbox',
                                                align: 'stretch'
                                            },
                                            padding: 0,
                                            border: 0,
                                            items:
                                            [
                                                 {
                                                     xtype: 'textfield',
                                                     name: 'ContactNumber1',
                                                     maxLength: 20,
                                                     width: '95%',
                                                     fieldLabel: '客户电话1',
                                                     labelWidth: '10.5%',
                                                     emptyText: '客户电话1',
                                                     allowBlank: true,
                                                     disabled: false
                                                 },
                                                 {
                                                     xtype: 'checkbox',
                                                     name: 'IsSendInfo1',
                                                     fieldLabel: '短信',
                                                     checked: true,
                                                     disabled: false,
                                                     inputValue: true
                                                 },
                                            ]
                                        },
                                        {
                                            xtype: 'fieldcontainer',
                                            width: '100%',
                                            defaultType: 'textfield',
                                            layout:
                                            {
                                                type: 'hbox',
                                                align: 'stretch'
                                            },
                                            padding: 0,
                                            border: 0,
                                            items:
                                            [
                                                 {
                                                     xtype: 'textfield',
                                                     name: 'ContactNumber2',
                                                     maxLength: 20,
                                                     width: '95%',
                                                     cls: 'Test',
                                                     fieldLabel: '客户电话2',
                                                     labelWidth: '10.5%',
                                                     emptyText: '客户电话2',
                                                     allowBlank: true,
                                                     disabled: false
                                                 },
                                                {
                                                    xtype: 'checkbox',
                                                    name: 'IsSendInfo2',
                                                    fieldLabel: '短信',
                                                    checked: true,
                                                    disabled: false,
                                                    inputValue: true
                                                }
                                            ]
                                        },

                                        {
                                            xtype: 'textfield',
                                            name: 'ContactEmail',
                                            maxLength: 20,
                                            width: '60%',
                                            cls: 'Test',
                                            fieldLabel: '客户邮箱',
                                            emptyText: '客户邮箱',
                                            allowBlank: true,
                                            disabled: false
                                        },
                                        {
                                            xtype: 'textfield',
                                            name: 'Operation_Code',
                                            maxLength: 20,
                                            columns: 2,
                                            width: '60%',
                                            cls: 'Test',
                                            fieldLabel: '作业编号',
                                            emptyText: '作业编号',
                                            allowBlank: true,
                                            disabled: false
                                        },
                                        {
                                            xtype: 'textfield',
                                            name: 'RegAddress',
                                            maxLength: 20,
                                            width: '60%',
                                            cls: 'Test',
                                            fieldLabel: '注册地址',
                                            emptyText: '注册地址',
                                            allowBlank: true,
                                            disabled: false
                                        },
                                        {
                                            xtype: 'textfield',
                                            name: 'YeZhiCode',
                                            maxLength: 20,
                                            width: '60%',
                                            cls: 'Test',
                                            fieldLabel: '营业执照编号',
                                            emptyText: '营业执照编号',
                                            allowBlank: true,
                                            disabled: false
                                        },
                                        {
                                            xtype: 'textfield',
                                            name: 'OrgCode',
                                            maxLength: 20,
                                            width: '60%',
                                            cls: 'Test',
                                            fieldLabel: '组织机构代码',
                                            emptyText: '组织机构代码',
                                            allowBlank: true,
                                            disabled: false
                                        },
                                        {
                                            xtype: 'textfield',
                                            name: 'ShiWCode',
                                            maxLength: 20,
                                            width: '60%',
                                            cls: 'Test',
                                            fieldLabel: '税务登记证编号',
                                            emptyText: '税务登记证编号',
                                            allowBlank: true,
                                            disabled: false
                                        },
                                        {
                                            xtype: 'fieldcontainer',
                                            fieldLabel: '必须材料',
                                            width: '100%',
                                            defaultType: 'textfield',
                                            layout: 'fit',
                                            padding: 0,
                                            border: 0,
                                            items:
                                            [
                                                {
                                                    xtype: 'grid',
                                                    height: 140,                                                   
                                                    store: me._FileFirstList,
                                                    stateful: false,
                                                    border: true,
                                                    cls: 'spms-grid',
                                                    itemId: 'spms-File-grid1',
                                                    forceFit: true,
                                                    autoScroll: true,
                                                    columnLines: true,
                                                    enableLocking: false,
                                                    unlockText: spms.resources.text_grid_column_unlock,
                                                    lockText: spms.resources.text_grid_column_lock,
                                                    viewConfig:
                                                    {
                                                        stripeRows: true,
                                                        loadingText: spms.resources.text_loading,
                                                        singleSelect: true
                                                    },
                                                    selModel:
                                                    {
                                                        selType: 'cellmodel'
                                                    },
                                                    bbar:
                                                    [
                                                        {
                                                            xtype: 'button',
                                                            text: '添加必须材料',
                                                            cls: 'spms-page-menu-button',
                                                            iconCls: 'spms-icon-add',
                                                            handler: OnAppendFile
                                                        }
                                                    ],
                                                    listeners:
                                                    {
                                                        select: OnRowSelectFile
                                                    },
                                                    columns:
                                                    [
                                                        {
                                                            xtype: 'actioncolumn',
                                                            menuDisabled: true,
                                                            text: '选择',
                                                            align: 'center',
                                                            sortable: false,
                                                            hideable: false,
                                                            padding: 0,
                                                            width: 80,
                                                            minWidth: 80,
                                                            items:
                                                            [
                                                                {
                                                                    //iconCls: 'spms-icon-upload',
                                                                    tooltip: '选择资料'
                                                                    //handler: OnRowSelectFile
                                                                }
                                                            ]
                                                        },
                                                        //{
                                                        //    text: '操作',
                                                        //    width: 80,
                                                        //    minWidth: 80,
                                                        //    sortable: true,
                                                        //    xtype: 'checkcolumn',
                                                        //    dataIndex: 'IsAssigned',
                                                        //    hideable: false,
                                                        //    align: 'center'
                                                        //},
                                                        {
                                                            text: '资料名称',
                                                            width: 200,
                                                            minWidth: 120,
                                                            sortable: false,
                                                            menuDisabled: true,
                                                            align: 'left',
                                                            dataIndex: 'FileType_Name',
                                                            hideable: false,
                                                            lockable: true,
                                                            editor:
                                                            {
                                                                xtype: 'textfield',
                                                                allowBlank: false,
                                                                maxLength: 40,
                                                                baseBodyCls: 'spms-cell-editor-textfield'
                                                            }
                                                        },
                                                        {
                                                            text: '有效期',
                                                            width: 280,
                                                            minWidth: 120,
                                                            sortable: false,
                                                            menuDisabled: true,
                                                            align: 'left',
                                                            dataIndex: 'DueDate',
                                                            hideable: false,
                                                            flex: 1,
                                                            editor:
                                                            {
                                                                xtype: 'textfield',
                                                                maxLength: 40,
                                                                baseBodyCls: 'spms-cell-editor-textfield'
                                                            }
                                                        },
                                                        {
                                                            text: '文件位置',
                                                            width: 280,
                                                            minWidth: 120,
                                                            sortable: false,
                                                            menuDisabled: true,
                                                            align: 'left',
                                                            dataIndex: 'FileType_Name',
                                                            hideable: false,
                                                            flex: 1,
                                                            editor:
                                                            {
                                                                xtype: 'textfield',
                                                                maxLength: 40,
                                                                baseBodyCls: 'spms-cell-editor-textfield'
                                                            }
                                                        },
                                                        {
                                                            xtype: 'actioncolumn',
                                                            menuDisabled: true,
                                                            text: '删除',
                                                            align: 'center',
                                                            sortable: false,
                                                            hideable: false,
                                                            padding: 0,
                                                            width: 80,
                                                            minWidth: 80,
                                                            items:
                                                            [
                                                                {
                                                                    iconCls: 'spms-icon-row-delete',
                                                                    tooltip: '删除资料',
                                                                    handler: OnDeleteImage
                                                                }
                                                            ]
                                                        },
                                                    ]
                                                }
                                            ]
                                        },
                                        {
                                            xtype: 'fieldcontainer',
                                            fieldLabel: '辅助材料',
                                            width: '100%',
                                            defaultType: 'textfield',
                                            layout: 'fit',
                                            padding: 0,
                                            border: 0,
                                            items:
                                            [
                                                {
                                                    xtype: 'grid',
                                                    height: 240,
                                                   
                                                    store: me.FileSecondList,
                                                    stateful: false,
                                                    border: true,
                                                    cls: 'spms-grid',
                                                    itemId: 'spms-File-grid2',                                                    
                                                    forceFit: true,
                                                    autoScroll: true,
                                                    columnLines: true,
                                                    enableLocking: false,
                                                    unlockText: spms.resources.text_grid_column_unlock,
                                                    lockText: spms.resources.text_grid_column_lock,
                                                    viewConfig:
                                                    {
                                                        stripeRows: true,
                                                        loadingText: spms.resources.text_loading,
                                                        singleSelect: true
                                                    },
                                                    selModel:
                                                    {
                                                        selType: 'cellmodel'
                                                    },
                                                    bbar:
                                                    [
                                                        {
                                                            xtype: 'button',
                                                            text: '添加辅助材料',
                                                            cls: 'spms-page-menu-button',
                                                            iconCls: 'spms-icon-add',
                                                            handler: OnAppendFile
                                                        }
                                                    ],
                                                    listeners:
                                                    {
                                                        select: OnRowSelectFile
                                                    },
                                                    columns:
                                                    [
                                                       {
                                                           xtype: 'actioncolumn',
                                                           menuDisabled: true,
                                                           text: '选择',
                                                           align: 'center',
                                                           sortable: false,
                                                           hideable: false,
                                                           padding: 0,
                                                           width: 80,
                                                           minWidth: 80,
                                                           items:
                                                           [
                                                               {
                                                                   //iconCls: 'spms-icon-row-delete',
                                                                   tooltip: '选择资料'
                                                                   //handler: OnRowSelectFile
                                                               }
                                                           ]
                                                       },
                                                        {
                                                            text: '资料名称',
                                                            width: 200,
                                                            minWidth: 120,
                                                            sortable: false,
                                                            menuDisabled: true,
                                                            align: 'left',
                                                            dataIndex: 'FileType_Name',
                                                            hideable: false,
                                                            lockable: true,
                                                            editor:
                                                            {
                                                                xtype: 'textfield',
                                                                allowBlank: false,
                                                                maxLength: 40,
                                                                baseBodyCls: 'spms-cell-editor-textfield'
                                                            }
                                                        },
                                                        {
                                                            text: '有效期',
                                                            width: 280,
                                                            minWidth: 120,
                                                            sortable: false,
                                                            menuDisabled: true,
                                                            align: 'left',
                                                            dataIndex: 'DueDate',
                                                            hideable: false,
                                                            flex: 1,
                                                            editor:
                                                            {
                                                                xtype: 'textfield',
                                                                maxLength: 40,
                                                                baseBodyCls: 'spms-cell-editor-textfield'
                                                            }
                                                        },
                                                        {
                                                            text: '文件位置',
                                                            width: 280,
                                                            minWidth: 120,
                                                            sortable: false,
                                                            menuDisabled: true,
                                                            align: 'left',
                                                            dataIndex: 'FileType_Name',
                                                            hideable: false,
                                                            flex: 1,
                                                            editor:
                                                            {
                                                                xtype: 'textfield',
                                                                maxLength: 40,
                                                                baseBodyCls: 'spms-cell-editor-textfield'
                                                            }
                                                        },
                                                        {
                                                            xtype: 'actioncolumn',
                                                            menuDisabled: true,
                                                            text: '删除',
                                                            align: 'center',
                                                            sortable: false,
                                                            hideable: false,
                                                            padding: 0,
                                                            width: 80,
                                                            minWidth: 80,
                                                            items:
                                                            [
                                                                {
                                                                    iconCls: 'spms-icon-row-delete',
                                                                    tooltip: '删除资料',
                                                                    handler: OnDeleteImage
                                                                }
                                                            ]
                                                        },
                                                    ]
                                                }
                                            ]
                                        },
                                         {
                                             xtype: 'fieldcontainer',
                                             fieldLabel: '附加图片',
                                             width: '100%',
                                             defaultType: 'textfield',
                                             layout: 'fit',
                                             padding: 0,
                                             border: 0,
                                             items:
                                             [
                                                {
                                                    xtype: 'grid',
                                                    name: 'gridImages',
                                                    itemId: 'gridImages',
                                                    height: 240,
                                                    store: _CurrentFileImages,
                                                    draggable: false,
                                                    stateful: false,
                                                    cls: 'spms-grid',
                                                    border: true,
                                                    forceFit: true,
                                                    autoScroll: true,
                                                    columnLines: true,
                                                    viewConfig:
                                                    {
                                                        stripeRows: true,
                                                        loadingText: spms.resources.text_loading,
                                                        singleSelect: true
                                                    },
                                                    bbar:
                                                    [
                                                        {
                                                            xtype: 'button',
                                                            text: '添加附加图片',
                                                            cls: 'spms-page-menu-button',
                                                            iconCls: 'spms-icon-add',
                                                            handler: OnAppendImage
                                                        }
                                                    ],
                                                    listeners:
                                                    {
                                                       // select: OnRowSelect
                                                    },
                                                    columns:
                                                    [
                                                        {
                                                            xtype: 'actioncolumn',
                                                            menuDisabled: true,
                                                            text: '操作',
                                                            align: 'center',
                                                            sortable: false,
                                                            hideable: false,
                                                            padding: 0,
                                                            width: 80,
                                                            minWidth: 80,
                                                            items:
                                                            [
                                                                {
                                                                    iconCls: 'spms-icon-view',
                                                                    tooltip: '查看图片',
                                                                    handler: OnViewImage
                                                                },
                                                                {
                                                                    iconCls: 'spms-icon-upload',
                                                                    tooltip: '上传图片',
                                                                    handler: OnUploadImage
                                                                },
                                                                {
                                                                    iconCls: 'spms-icon-row-delete',
                                                                    tooltip: '删除图片',
                                                                    handler: OnDeleteImage
                                                                }
                                                            ]
                                                        },
                                                        {
                                                            text: '序号',
                                                            width: 100,
                                                            minWidth: 120,
                                                            sortable: true,
                                                            align: 'left',
                                                            dataIndex: 'File_Order',
                                                            hideable: false,
                                                            flex: 1,
                                                            editor:
                                                            {
                                                                xtype: 'textfield',
                                                                maxLength: 40,
                                                                baseBodyCls: 'spms-cell-editor-textfield'
                                                            }
                                                        }
                                                    ]
                                                }
                                             ]
                                         }
                                    ],
                                    dockedItems:
                                    [
                                        {
                                            xtype: 'toolbar',
                                            dock: 'bottom',
                                            ui: 'footer',
                                            cls: 'spms-page-card-detail-toolbar',
                                            padding: '15 0 3 0',
                                            items:
                                            [
                                                '->',
                                                {
                                                    text: '连续新增',
                                                    xtype: 'button',
                                                    cls: 'spms-page-card-detail-toolbar-button',
                                                    handler: function () {
                                                        //执行新增操作
                                                        DoAdd.call(me, true);
                                                    }
                                                },

                                                {
                                                    text: '新增',
                                                    xtype: 'button',
                                                    cls: 'spms-page-card-detail-toolbar-button',
                                                    handler: function () {
                                                        //执行新增操作
                                                        DoAdd.call(me, false);
                                                    }
                                                },
                                                {
                                                    text: '取消',
                                                    xtype: 'button',
                                                    cls: 'spms-page-card-detail-toolbar-button',
                                                    handler: function () {
                                                        //启用工具栏
                                                        toolbar.setDisabled(false);

                                                        //返回一览标签
                                                        card.getLayout().setActiveItem('spms-card-list');
                                                    }
                                                }
                                            ]
                                        }
                                    ]
                                }
                            ]
                        }
                    );
                    //添加到面板
                    card.add(me._Panel_Create);
                }

                //禁用工具栏
                toolbar.setDisabled(true);

                //切换到面板
                card.getLayout().setActiveItem('spms-card-create');
            }

            //处理删除按钮点击事件
            function OnRemove(sender) {
                //判断是否选中记录
                if (!spms.common.IsValid(_CurrentRecord)) {
                    return;
                }

                //询问是否确定删除
                Ext.Msg.show
                (
                    {
                        title: spms.resources.text_app_title,
                        msg: '确定要删除备注为"' + _CurrentRecord.get('Memo') + '"吗?',
                        buttons: Ext.Msg.YESNO,
                        icon: Ext.Msg.QUESTION,
                        autoScroll: true,
                        closeAction: 'destroy',
                        fn: function (button, text, eOpts) {
                            //判断是否确定删除 
                            if (button == 'yes') {
                                //创建请求对象
                                Ext.Ajax.request
                                (
                                    {
                                        url: spms.url.Action('Delete', 'ActiveOperation'),
                                        method: spms.constant.HttpMethod.POST,
                                        jsonData: _CurrentRecord.data,
                                        callback: function (options, success, response) {
                                            //处理错误
                                            if (spms.exception.HandleAjaxRequestError(options, success, response)) {
                                                //刷新数据
                                                Refresh();
                                            }
                                        }
                                    }
                                );
                            }
                        }
                    }
                );
            }

            //处理查看图片事件
            function OnViewImage(grid, rowIndex, colIndex) {
                //获得存储对象
                var store = grid.getStore();

                //获得对应的记录
                var record = store.getAt(rowIndex);

                //判断记录是否存在
                if (!spms.common.IsValid(record)) {
                    return;
                }

                //判断是否已经上传了图片
                if (!record.get('HasContent')) {
                    //如果没有内容，则直接返回
                    return;
                }
                //用于保存参数
                var params =
                [
                    { Name: 'File_ID', Value: record.get('File_ID') },
                    { Name: 'IsNew', Value: record.get('IsNew') }
                ];

                //用于保存参数
                var options =
                {
                    url: spms.url.Action('GetImage', 'Packaging', params),
                    title: record.get('File_Title')
                };

                //显示预览
                spms.common.Preview(options);
            }

           
            //处理添加图片事件
            function OnAppendFile(sender, eOpts) {
                //获得表格对象
                var grid = sender.up('grid');

                //判断是否有效
                if (!spms.common.IsValid(grid)) {
                    //直接返回
                    return;
                }
                
                //获得存储对象
                var store = grid.getStore();

                //判断是否有效
                if (!spms.common.IsValid(store)) {
                    //直接返回
                    return;
                }
                
                //添加空白数据
                store.add
                (
                    Ext.create
                    (
                        'ActiveOperationFiles',
                        {
                            File_ID: spms.common.NewGuid(),
                            Operation_ID: '',
                            FileType_ID: '',
                            IsDelayedDelivery: '',
                            DueDate: '',
                            Memo: '',
                            Files: []
                                                       
                        }
                    )
                );
            }

            //执行新增图片操作
            function OnAppendImage(sender, eOpts) {
                if (_CurrentFile == undefined) {
                    alert("请选择一种材料");
                    return;
                }
                
                //获得表格对象
                var grid = sender.up('grid');
                //获得存储对象
                var store = grid.getStore();
                var count = store.getCount();
                //判断是否有效
                if (!spms.common.IsValid(store)) {
                    //直接返回
                    return;
                }
                //添加空白数据
                store.add
                (
                    Ext.create
                    (
                        'UploadFile',
                        {
                            File_ID: spms.common.NewGuid(),
                            File_Title: '封装图片',
                            HasContent: false,
                            IsNew: true,
                            File_Order: count + 1
                        }
                    )
                );
                //var item = Ext.create('UploadFile');
                //item.File_ID = 12;
                //var item1 = Ext.create('UploadFile');
                //item1.File_ID = 12;
                //var items = [];
                //items.push(item);
                //items.push(item1);
                _CurrentFile.set("Files", grid.getStore().data.items);
            }

            //处理上传图片事件
            function OnUploadImage(grid, rowIndex, colIndex) {
                //获得存储对象
                var store = grid.getStore();

                ////判断是否有效
                //if (!spms.common.IsValid(store)) {
                //    //直接返回
                //    return;
                //}

                //获得对应的记录
                var record = store.getAt(rowIndex);

                //判断是否有效
                if (!spms.common.IsValid(record)) {
                    //直接返回
                    return;
                }

                //上传文件
                spms.common.UploadFile
                (
                    {
                        file_types: '*.bmp;*.png;*.jpg;*.jpeg;*.jpe;*.jfif;*.gif',
                        file_types_description: 'Image Files(*.bmp;*.png;*.jpg;*.jpeg;*.jpe;*.jfif;*.gif)',
                        file_size_limit: '2 MB',
                        file_size_limit_tip: '小于2MB的图片文件',
                        callback: OnUploadImageCallback,
                        title: '上传图片',
                        _record: record
                    }
                );
            }
            //图片上传完成回调
            function OnUploadImageCallback(response, options) {
                //判断是否成功
                if (!response.success) {
                    //直接返回
                    return;
                }

                //获得记录
                var record = options._record;

                //获得上传文件编号
                if (response.data && response.data.length > 0 && record) {
                    //获得文件编号
                    var tempFileID = response.data[0];

                    //更新记录
                    record.set('File_ID', tempFileID);
                    record.set('HasContent', true);
                    record.set('IsNew', true);
                }
            }

            //处理删除文件事件
            function OnDeleteImage(grid, rowIndex, colIndex) {
                //获得存储对象
                var store = grid.getStore();
                //获得对应的记录
                var record = store.getAt(rowIndex);
                //提示信息
                Ext.MessageBox.show
                (
                    {
                        title: spms.resources.text_app_title,
                        msg: '确定要删除名为\"' + record.get('File_Title') + '\"的图片吗？',
                        buttons: Ext.Msg.YESNO,
                        icon: Ext.Msg.QUESTION,
                        autoScroll: true,
                        closeAction: 'destroy',
                        fn: function (buttonId, text, eOpts) {
                            //判断是否安装
                            if (buttonId == 'yes') {
                                //判断是否有效
                                if (!spms.common.IsValid(store)) {
                                    //直接返回
                                    return;
                                }
                                //删除对应记录
                                store.removeAt(rowIndex);
                            }
                        }
                    }
                );
            }

            //处理资料表格行选中事件
            function OnRowSelectFile(panel, record, index, options) {
                //记录当前选中记录
                _CurrentFile = record;

                if (_CurrentFile.get("Files") == undefined) {
                    _CurrentFile.set("Files", []);
                }
                //取出当前文件的资料集合
                _CurrentFileImages = _CurrentFile.get("Files");

                _Panel_Create = card.down('#spms-card-create');
                if (typeof _Panel_Create != 'undefined') {
                    var grid = _Panel_Create.down('#gridImages');
                    var store = grid.getStore();
                    //判断是否有效
                    if (!spms.common.IsValid(store)) {
                        //直接返回
                        return;
                    }
                    store.loadData(_CurrentFileImages);

                }

                //更新按钮状态
                //UpdateButtonState(record);
            }

            //处理表格行选中事件
            function OnRowSelect(panel, record, index, options) {
                //记录当前选中记录
                _CurrentRecord = record;

                //更新按钮状态
                UpdateButtonState(record);
            }

            //处理编辑按钮点击事件
            function OnEdit(sender) {
                //判断是否选中记录
                if (!spms.common.IsValid(_CurrentRecord)) {
                    //如果没有选中记录，则直接返回
                    return;
                }

                //获得当前对象
                var me = this;
                _CurrentFileImages = [];
                //判断窗体是否已经初始化
                if (typeof me._Panel_Edit == 'undefined') {
                    //创建必要文件存储
                    me._FileFirstList = Ext.create
                    (
                        'Ext.data.Store',
                        {
                            pageSize: 0,
                            autoSync: false,
                            autoLoad: true,
                            root: 'data',
                            remoteFilter: true,
                            remoteSort: false,
                            filters: [{ property: 'Operation_ID@E', value: _CurrentRecord.get('Operation_ID') }],
                            sorters: [{ property: 'Operation_ID', direction: 'ASC' }],
                            model: 'ActiveOperationFiles',
                            proxy:
                            {
                                type: 'ajax',
                                batchActions: false,
                                url: spms.url.Action('ListFiles', 'ActiveOperation'),
                                reader:
                                {
                                    type: 'json',
                                    root: 'data'
                                },
                                listeners:
                                {
                                    //处理代理异常
                                    exception: spms.exception.HandleProxyError
                                }
                            }
                        }
                    );

                    //创建辅助文件存储              

                    me._FileSecondList = Ext.create
                    (
                        'Ext.data.Store',
                        {
                            pageSize: 0,
                            autoSync: false,
                            autoLoad: true,
                            root: 'data',
                            remoteFilter: true,
                            remoteSort: false,
                            filters: [{ property: 'Operation_ID@E', value: _CurrentRecord.get('Operation_ID') }],
                            sorters: [{ property: 'Operation_ID', direction: 'ASC' }],
                            model: 'ActiveOperationFiles',
                            proxy:
                            {
                                type: 'ajax',
                                batchActions: false,
                                url: spms.url.Action('ListFiles', 'ActiveOperation'),
                                reader:
                                {
                                    type: 'json',
                                    root: 'data'
                                },
                                listeners:
                                {
                                    //处理代理异常
                                    exception: spms.exception.HandleProxyError
                                }
                            }
                        }
                    );
                    //创建新增面板
                    me._Panel_Edit = Ext.create
                    (
                        'Ext.panel.Panel',
                        {
                            layout: 'fit',
                            id: 'spms-card-edit',
                            cls: 'spms-page-card-detail',
                            border: false,
                            header:
                            {
                                title: '编辑账户',
                                border: false,
                                height: 36,
                                cls: 'spms-page-card-detail-header'
                            },
                            listeners:
                            {
                                //挂接显示事件
                                show: function (panel, options) {
                                    //获得面板
                                    var panel = me._Panel_Edit;

                                    //获得表单
                                    var form = panel.down('form');

                                    //获得预览面板
                                    var panelSignaturePreview = panel.down('#SignaturePreview');

                                    //判断是否存在
                                    if (spms.common.IsValid(form)) {
                                        //重置内容
                                        form.getForm().reset();

                                        //判断是否有效
                                        if (spms.common.IsValid(panelSignaturePreview)) {
                                            //显示预览图
                                            panelSignaturePreview.setSrc(Ext.BLANK_IMAGE_URL);
                                        }

                                        //提交数据
                                        form.load
                                        (
                                            {
                                                url: spms.url.Action('Detail', 'ActiveOperation'),
                                                method: spms.constant.HttpMethod.Get,
                                                params: { Operation_ID: _CurrentRecord.get('Operation_ID'), Operation_Code: _CurrentRecord.get('Operation_Code') },                                               
                                                waitTitle: spms.resources.text_loading_title,
                                                waitMsg: spms.resources.text_loading,
                                                success: function (panel, action) {
                                                    //处理错误
                                                    if (spms.exception.HandleSuccessError(panel, action)) {
                                                        //判断是否有预览图片
                                                        //var txtHasSignature = form.down('#HasSignature');

                                                        //判断是否有效
                                                        //if (spms.common.IsValid(txtHasSignature)) {
                                                        //    //判断是否有签名图
                                                        //    if (txtHasSignature.getValue() == 'true') {
                                                        //        //用于保存参数
                                                        //        var params =
                                                        //        [
                                                        //            { Name: 'User_ID', Value: _CurrentRecord.get('User_ID') }
                                                        //        ];

                                                        //        //获得图片地址
                                                        //        var imageUrl = spms.url.Action('GetSignatureImage', 'Account', params);

                                                        //        //显示预览图
                                                        //        panelSignaturePreview.setSrc(imageUrl);
                                                        //    }
                                                        //}

                                                        //设置焦点
                                                        form.down('field').focus(false, 100);
                                                    }
                                                    else {
                                                        //启用工具栏
                                                        toolbar.setDisabled(false);

                                                        //返回一览标签
                                                        card.getLayout().setActiveItem('spms-card-list');
                                                    }
                                                },
                                                failure: function (form, action) {
                                                    //处理错误
                                                    spms.exception.HandleFailureError(form, action);

                                                    //启用工具栏
                                                    toolbar.setDisabled(false);

                                                    //返回一览标签
                                                    card.getLayout().setActiveItem('spms-card-list');
                                                }
                                            }
                                        );
                                    }
                                }
                            },
                            items:
                            [
                                {
                                    xtype: 'form',
                                    autoScroll: true,
                                    frame: false,
                                    method: 'POST',
                                    waitMsgTarget: true,
                                    waitTitle: spms.resources.text_app_title,
                                    bodyPadding: 12,
                                    bodyCls: 'spms-page-card-detail-form-body',
                                    bodyBorder: false,
                                    border: false,
                                    defaultType: 'textfield',
                                    fieldDefaults:
                                   {
                                       labelAlign: 'left',
                                       labelWidth: '10%',
                                       anchor: '100%',
                                       msgTarget: 'qtip'
                                   },
                                    items:
                                    [
                                        {
                                            xtype: 'hiddenfield',
                                            name: 'User_ID'
                                        },
                                       {
                                           xtype: 'textfield',
                                           width: '101%',
                                           name: 'CompanyName',
                                           maxLength: 40,
                                           minLength: 4,
                                           fieldLabel: '企业名称',
                                           emptyText: '企业名称',
                                           allowBlank: false,
                                           disabled: false
                                       },
                                        {
                                            xtype: 'textfield',
                                            name: 'ContactPerson',
                                            width: '60%',
                                            fieldLabel: '企业法人',
                                            emptyText: '企业法人',
                                            allowBlank: false,
                                            disabled: false
                                        },
                                        {
                                            xtype: 'fieldcontainer',
                                            width: '100%',
                                            defaultType: 'textfield',
                                            layout:
                                            {
                                                type: 'hbox',
                                                align: 'stretch'
                                            },
                                            padding: 0,
                                            border: 0,
                                            items:
                                            [
                                                 {
                                                     xtype: 'textfield',
                                                     name: 'ContactNumber1',
                                                     maxLength: 20,
                                                     width: '95%',
                                                     fieldLabel: '客户电话1',
                                                     labelWidth: '10.5%',
                                                     emptyText: '客户电话1',
                                                     allowBlank: true,
                                                     disabled: false
                                                 },
                                                 {
                                                     xtype: 'checkbox',
                                                     name: 'IsSendInfo1',
                                                     fieldLabel: '短信',
                                                     checked: true,
                                                     disabled: false,
                                                     inputValue: true
                                                 },
                                            ]
                                        },
                                        {
                                            xtype: 'fieldcontainer',
                                            width: '100%',
                                            defaultType: 'textfield',
                                            layout:
                                            {
                                                type: 'hbox',
                                                align: 'stretch'
                                            },
                                            padding: 0,
                                            border: 0,
                                            items:
                                            [
                                                 {
                                                     xtype: 'textfield',
                                                     name: 'ContactNumber2',
                                                     maxLength: 20,
                                                     width: '95%',
                                                     cls: 'Test',
                                                     fieldLabel: '客户电话2',
                                                     labelWidth: '10.5%',
                                                     emptyText: '客户电话2',
                                                     allowBlank: true,
                                                     disabled: false
                                                 },
                                                {
                                                    xtype: 'checkbox',
                                                    name: 'IsSendInfo2',
                                                    fieldLabel: '短信',
                                                    checked: true,
                                                    disabled: false,
                                                    inputValue: true
                                                }
                                            ]
                                        },
                                        {
                                            xtype: 'textfield',
                                            name: 'ContactEmail',
                                            maxLength: 20,
                                            width: '60%',
                                            fieldLabel: '客户邮箱',
                                            emptyText: '客户邮箱',
                                            allowBlank: true,
                                            disabled: false
                                        },
                                        {
                                            xtype: 'textfield',
                                            name: 'Operation_Code',
                                            maxLength: 20,
                                            columns: 2,
                                            width: '60%',
                                            fieldLabel: '作业编号',
                                            emptyText: '作业编号',
                                            allowBlank: true,
                                            disabled: false
                                        },
                                        {
                                            xtype: 'textfield',
                                            name: 'RegAddress',
                                            maxLength: 20,
                                            width: '60%',
                                            fieldLabel: '注册地址',
                                            emptyText: '注册地址',
                                            allowBlank: true,
                                            disabled: false
                                        },
                                        {
                                            xtype: 'textfield',
                                            name: 'YeZhiCode',
                                            maxLength: 20,
                                            width: '60%',
                                            fieldLabel: '营业执照编号',
                                            emptyText: '营业执照编号',
                                            allowBlank: true,
                                            disabled: false
                                        },
                                        {
                                            xtype: 'textfield',
                                            name: 'OrgCode',
                                            maxLength: 20,
                                            width: '60%',
                                            fieldLabel: '组织机构代码',
                                            emptyText: '组织机构代码',
                                            allowBlank: true,
                                            disabled: false
                                        },
                                        {
                                            xtype: 'textfield',
                                            name: 'ShiWCode',
                                            maxLength: 20,
                                            width: '60%',
                                            fieldLabel: '税务登记证编号',
                                            emptyText: '税务登记证编号',
                                            allowBlank: true,
                                            disabled: false
                                        },
                                        {
                                            xtype: 'textfield',
                                            name: 'Memo',
                                            maxLength: 20,
                                            width: '60%',
                                            fieldLabel: '备注',
                                            emptyText: '备注',
                                            allowBlank: true,
                                            disabled: false
                                        },
                                        {
                                            xtype: 'fieldcontainer',
                                            fieldLabel: '必须材料',
                                            width: '100%',
                                            defaultType: 'textfield',
                                            layout: 'fit',
                                            padding: 0,
                                            border: 0,
                                            items:
                                            [
                                                {
                                                    xtype: 'grid',
                                                    height: 240,
                                                    plugins:
                                                    [
                                                       new Ext.grid.plugin.CellEditing
                                                        (
                                                            {
                                                                clicksToEdit: 1
                                                            }
                                                        )
                                                    ],
                                                    store: me._FileFirstList,
                                                    stateful: false,
                                                    border: true,
                                                    cls: 'spms-grid',
                                                    itemId: 'spms-images-grid1',
                                                    forceFit: true,
                                                    autoScroll: true,
                                                    columnLines: true,
                                                    enableLocking: false,
                                                    unlockText: spms.resources.text_grid_column_unlock,
                                                    lockText: spms.resources.text_grid_column_lock,
                                                    viewConfig:
                                                    {
                                                        stripeRows: true,
                                                        loadingText: spms.resources.text_loading,
                                                        singleSelect: true
                                                    },
                                                    selModel:
                                                    {
                                                        selType: 'cellmodel'
                                                    },
                                                    bbar:
                                                    [
                                                        {
                                                            xtype: 'button',
                                                            text: '添加必须材料',
                                                            cls: 'spms-page-menu-button',
                                                            iconCls: 'spms-icon-add',
                                                            handler: OnAppendFile
                                                        }
                                                    ],
                                                    listeners:
                                                    {
                                                        //select: OnRowSelectFile
                                                    },
                                                    columns:
                                                    [
                                                        {
                                                            xtype: 'actioncolumn',
                                                            menuDisabled: true,
                                                            text: '选择',
                                                            align: 'center',
                                                            sortable: false,
                                                            hideable: false,
                                                            padding: 0,
                                                            width: 80,
                                                            minWidth: 80,
                                                            items:
                                                            [
                                                                {
                                                                    //iconCls: 'spms-icon-row-delete',
                                                                    tooltip: '选择资料',
                                                                    handler: OnRowSelectFile
                                                                }
                                                            ]
                                                        },
                                                        //{
                                                        //    text: '操作',
                                                        //    width: 80,
                                                        //    minWidth: 80,
                                                        //    sortable: true,
                                                        //    xtype: 'checkcolumn',
                                                        //    dataIndex: 'IsAssigned',
                                                        //    hideable: false,
                                                        //    align: 'center'
                                                        //},
                                                        {
                                                            text: '资料名称',
                                                            width: 200,
                                                            minWidth: 120,
                                                            sortable: false,
                                                            menuDisabled: true,
                                                            align: 'left',
                                                            dataIndex: 'FileType_Name',
                                                            hideable: false,
                                                            lockable: true,
                                                            editor:
                                                            {
                                                                xtype: 'textfield',
                                                                allowBlank: false,
                                                                maxLength: 40,
                                                                baseBodyCls: 'spms-cell-editor-textfield'
                                                            }
                                                        },
                                                        {
                                                            text: '有效期',
                                                            width: 280,
                                                            minWidth: 120,
                                                            sortable: false,
                                                            menuDisabled: true,
                                                            align: 'left',
                                                            dataIndex: 'DueDate',
                                                            hideable: false,
                                                            flex: 1,
                                                            editor:
                                                            {
                                                                xtype: 'textfield',
                                                                maxLength: 40,
                                                                baseBodyCls: 'spms-cell-editor-textfield'
                                                            }
                                                        },
                                                        {
                                                            text: '文件位置',
                                                            width: 280,
                                                            minWidth: 120,
                                                            sortable: false,
                                                            menuDisabled: true,
                                                            align: 'left',
                                                            dataIndex: 'FileType_Name',
                                                            hideable: false,
                                                            flex: 1,
                                                            editor:
                                                            {
                                                                xtype: 'textfield',
                                                                maxLength: 40,
                                                                baseBodyCls: 'spms-cell-editor-textfield'
                                                            }
                                                        },
                                                        {
                                                            xtype: 'actioncolumn',
                                                            menuDisabled: true,
                                                            text: '删除',
                                                            align: 'center',
                                                            sortable: false,
                                                            hideable: false,
                                                            padding: 0,
                                                            width: 80,
                                                            minWidth: 80,
                                                            items:
                                                            [
                                                                {
                                                                    iconCls: 'spms-icon-row-delete',
                                                                    tooltip: '删除资料',
                                                                    handler: OnDeleteImage
                                                                }
                                                            ]
                                                        },
                                                    ]
                                                }
                                            ]
                                        },
                                        {
                                            xtype: 'fieldcontainer',
                                            fieldLabel: '辅助材料',
                                            width: '100%',
                                            defaultType: 'textfield',
                                            layout: 'fit',
                                            padding: 0,
                                            border: 0,
                                            items:
                                            [
                                                {
                                                    xtype: 'grid',
                                                    height: 240,
                                                    plugins:
                                                    [
                                                       new Ext.grid.plugin.CellEditing
                                                        (
                                                            {
                                                                clicksToEdit: 1
                                                            }
                                                        )
                                                    ],
                                                    store: me._FileSecondList,
                                                    stateful: false,
                                                    border: true,
                                                    cls: 'spms-grid',
                                                    itemId: 'spms-images-grid2',
                                                    forceFit: true,
                                                    autoScroll: true,
                                                    columnLines: true,
                                                    enableLocking: false,
                                                    unlockText: spms.resources.text_grid_column_unlock,
                                                    lockText: spms.resources.text_grid_column_lock,
                                                    viewConfig:
                                                    {
                                                        stripeRows: true,
                                                        loadingText: spms.resources.text_loading,
                                                        singleSelect: true
                                                    },
                                                    selModel:
                                                    {
                                                        selType: 'cellmodel'
                                                    },
                                                    bbar:
                                                    [
                                                        {
                                                            xtype: 'button',
                                                            text: '添加辅助材料',
                                                            cls: 'spms-page-menu-button',
                                                            iconCls: 'spms-icon-add',
                                                            handler: OnAppendFile
                                                        }
                                                    ],
                                                    listeners:
                                                    {
                                                        select: OnRowSelectFile
                                                    },
                                                    columns:
                                                    [
                                                       {
                                                           xtype: 'actioncolumn',
                                                           menuDisabled: true,
                                                           text: '选择',
                                                           align: 'center',
                                                           sortable: false,
                                                           hideable: false,
                                                           padding: 0,
                                                           width: 80,
                                                           minWidth: 80,
                                                           items:
                                                           [
                                                               {
                                                                  // iconCls: 'spms-icon-row-delete',
                                                                   tooltip: '选择资料',
                                                                   handler: OnRowSelectFile
                                                               }
                                                           ]
                                                       },
                                                        {
                                                            text: '资料名称',
                                                            width: 200,
                                                            minWidth: 120,
                                                            sortable: false,
                                                            menuDisabled: true,
                                                            align: 'left',
                                                            dataIndex: 'FileType_Name',
                                                            hideable: false,
                                                            lockable: true,
                                                            editor:
                                                            {
                                                                xtype: 'textfield',
                                                                allowBlank: false,
                                                                maxLength: 40,
                                                                baseBodyCls: 'spms-cell-editor-textfield'
                                                            }
                                                        },
                                                        {
                                                            text: '有效期',
                                                            width: 280,
                                                            minWidth: 120,
                                                            sortable: false,
                                                            menuDisabled: true,
                                                            align: 'left',
                                                            dataIndex: 'DueDate',
                                                            hideable: false,
                                                            flex: 1,
                                                            editor:
                                                            {
                                                                xtype: 'textfield',
                                                                maxLength: 40,
                                                                baseBodyCls: 'spms-cell-editor-textfield'
                                                            }
                                                        },
                                                        {
                                                            text: '文件位置',
                                                            width: 280,
                                                            minWidth: 120,
                                                            sortable: false,
                                                            menuDisabled: true,
                                                            align: 'left',
                                                            dataIndex: 'FileType_Name',
                                                            hideable: false,
                                                            flex: 1,
                                                            editor:
                                                            {
                                                                xtype: 'textfield',
                                                                maxLength: 40,
                                                                baseBodyCls: 'spms-cell-editor-textfield'
                                                            }
                                                        },
                                                        {
                                                            xtype: 'actioncolumn',
                                                            menuDisabled: true,
                                                            text: '删除',
                                                            align: 'center',
                                                            sortable: false,
                                                            hideable: false,
                                                            padding: 0,
                                                            width: 80,
                                                            minWidth: 80,
                                                            items:
                                                            [
                                                                {
                                                                    iconCls: 'spms-icon-row-delete',
                                                                    tooltip: '删除资料',
                                                                    handler: OnDeleteImage
                                                                }
                                                            ]
                                                        },
                                                    ]
                                                }
                                            ]
                                        },
                                         {
                                             xtype: 'fieldcontainer',
                                             fieldLabel: '附加图片',
                                             width: '100%',
                                             defaultType: 'textfield',
                                             layout: 'fit',
                                             padding: 0,
                                             border: 0,
                                             items:
                                             [
                                                {
                                                    xtype: 'grid',
                                                    name: 'gridImages',
                                                    itemId: 'gridImages',
                                                    height: 240,
                                                    store: _CurrentFileImages,
                                                    draggable: false,
                                                    stateful: false,
                                                    cls: 'spms-grid',
                                                    border: true,
                                                    forceFit: true,
                                                    autoScroll: true,
                                                    columnLines: true,
                                                    viewConfig:
                                                    {
                                                        stripeRows: true,
                                                        loadingText: spms.resources.text_loading,
                                                        singleSelect: true
                                                    },
                                                    bbar:
                                                    [
                                                        {
                                                            xtype: 'button',
                                                            text: '添加附加图片',
                                                            cls: 'spms-page-menu-button',
                                                            iconCls: 'spms-icon-add',
                                                            handler: OnAppendImage
                                                        }
                                                    ],
                                                    listeners:
                                                    {
                                                        //select: OnRowSelect
                                                    },
                                                    columns:
                                                    [
                                                        {
                                                            xtype: 'actioncolumn',
                                                            menuDisabled: true,
                                                            text: '操作',
                                                            align: 'center',
                                                            sortable: false,
                                                            hideable: false,
                                                            padding: 0,
                                                            width: 80,
                                                            minWidth: 80,
                                                            items:
                                                            [
                                                                {
                                                                    iconCls: 'spms-icon-view',
                                                                    tooltip: '查看图片',
                                                                    handler: OnViewImage
                                                                },
                                                                {
                                                                    iconCls: 'spms-icon-upload',
                                                                    tooltip: '上传图片',
                                                                    handler: OnUploadImage
                                                                },
                                                                {
                                                                    iconCls: 'spms-icon-row-delete',
                                                                    tooltip: '删除图片',
                                                                    handler: OnDeleteImage
                                                                }
                                                            ]
                                                        },
                                                        {
                                                            text: '序号',
                                                            width: 100,
                                                            minWidth: 120,
                                                            sortable: true,
                                                            align: 'left',
                                                            dataIndex: 'File_Order',
                                                            hideable: false,
                                                            flex: 1,
                                                            editor:
                                                            {
                                                                xtype: 'textfield',
                                                                maxLength: 40,
                                                                baseBodyCls: 'spms-cell-editor-textfield'
                                                            }
                                                        }
                                                    ]
                                                }
                                             ]
                                         }
                                    ],
                                    dockedItems:
                                    [
                                        {
                                            xtype: 'toolbar',
                                            dock: 'bottom',
                                            ui: 'footer',
                                            cls: 'spms-page-card-detail-toolbar',
                                            padding: '15 0 3 0',
                                            items:
                                            [
                                                '->',
                                                {
                                                    text: '保存',
                                                    xtype: 'button',
                                                    cls: 'spms-page-card-detail-toolbar-button',
                                                    handler: function () {
                                                        //获得表单
                                                        var form = me._Panel_Edit.down('form');

                                                       

                                                        //判断表单是否有效
                                                        if (form) {
                                                            //获得表单对象
                                                            var formBase = form.getForm();

                                                            //检查数据是否合法
                                                            if (formBase.isValid()) {
                                                                //提交数据
                                                                formBase.submit
                                                                (
                                                                    {
                                                                        url: spms.url.Action('Update', 'ActiveOperation'),
                                                                        method: spms.constant.HttpMethod.Post,
                                                                        //params: { Roles: postParams },
                                                                        submitEmptyText: false,
                                                                        waitTitle: spms.resources.text_submitting_title,
                                                                        waitMsg: spms.resources.text_submitting,
                                                                        success: function (panel, action) {
                                                                            //处理提交错误
                                                                            if (spms.exception.HandleSuccessError(panel, action)) {
                                                                                //启用工具栏
                                                                                toolbar.setDisabled(false);

                                                                                //返回一览标签
                                                                                card.getLayout().setActiveItem('spms-card-list');

                                                                                //刷新数据
                                                                                Refresh();
                                                                            }
                                                                        },
                                                                        failure: spms.exception.HandleFailureError
                                                                    }
                                                                );
                                                            }
                                                        }
                                                    }
                                                },
                                                {
                                                    text: '取消',
                                                    xtype: 'button',
                                                    cls: 'spms-page-card-detail-toolbar-button',
                                                    handler: function () {
                                                        //启用工具栏
                                                        toolbar.setDisabled(false);

                                                        //返回一览标签
                                                        card.getLayout().setActiveItem('spms-card-list');
                                                    }
                                                }
                                            ]
                                        }
                                    ]
                                }
                            ]
                        }
                    );
                    //添加到面板
                    card.add(me._Panel_Edit);
                }

                //禁用工具栏
                toolbar.setDisabled(true);

                //切换到面板
                card.getLayout().setActiveItem('spms-card-edit');

                
            }

            //处理状态变更按钮点击事件
            function OnChangeState(sender) {
                //判断是否选中记录
                if (!spms.common.IsValid(_CurrentRecord)) {
                    return;
                }
                //用于保存提示消息
                var msg = '';

                ////判断是否启用
                //if (_CurrentRecord.get('IsEnabled')) {
                //    //设置提示信息
                //    msg = msg.concat('确定要停用选中的账户"', _CurrentRecord.get('LoginName'), '"吗？<br\><br\>注意：账户一旦停用，则无法使用该账号登陆系统。')
                //}
                //else {
                //    //设置提示信息
                //    msg = msg.concat('确定要启用选中的账户"', _CurrentRecord.get('LoginName'), '"吗？<br\><br\>注意：账户一旦启用，则可以使用该账号登陆系统。')
                //}

                //创建参数
                //var options =
                //{
                //    msg: msg,
                //    url: spms.url.Action('ChangeState', 'ActiveOperation'),
                //    params: _CurrentRecord.data,
                //    callback: OnAjaxRequestCallback
                //}

                ////执行请求
                //spms.common.DoAjaxRequestWithConfirm(options);
            }

            
            
            //Ajax回调
            function OnAjaxRequestCallback(options) {
                //刷新数据
                Refresh();
            }

            //刷新数据
            function Refresh(options) {
                //刷新数据
                store.load(options);
            }

            //处理表格行选中事件
            function OnRowSelect(panel, record, index, options) {
                //记录当前选中记录
                _CurrentRecord = record;

                //更新按钮状态
                UpdateButtonState(record);
            }

            //上传文件
            function UploadFile(panel) {
                //上传文件
                spms.common.UploadFile
                (
                    {
                        file_types: '*.bmp;*.png;*.jpg;*.jpeg;*.jpe;*.jfif;*.gif',
                        file_types_description: 'Image Files(*.bmp;*.png;*.jpg;*.jpeg;*.jpe;*.jfif;*.gif)',
                        file_size_limit: '2 MB',
                        file_size_limit_tip: '小于2MB的图片文件',
                        callback: OnUploadImageCallback,
                        _Panel: panel
                    }
                );
            }

            //图片上传完成回调
            function OnUploadImageCallback(response, options) {
                //判断是否成功
                if (!response.success) {
                    //直接返回
                    return;
                }

                //获得面板
                var panel = options._Panel;

                //获得上传文件编号
                if (response.data && response.data.length > 0 && panel) {
                    //获得文件编号
                    var tempFileID = response.data[0];

                    //获得字段
                    var txtHasSignature = panel.down('#HasSignature');
                    var txtSignatureID = panel.down('#Signature_ID');
                    var panelSignaturePreview = panel.down('#SignaturePreview');

                    //更新值
                    txtHasSignature.setValue(true);
                    txtSignatureID.setValue(tempFileID);

                    //用于保存参数
                    var params =
                    [
                        { Name: 'FileID', Value: tempFileID },
                        { Name: 'Format', Value: 'png' },
                        { Name: 'Width', Value: panelSignaturePreview.maxWidth },
                        { Name: 'Height', Value: panelSignaturePreview.maxHeight }
                    ];

                    //获得图片地址
                    var imageUrl = spms.url.Action('GetTempImage', 'Common', params);

                    //显示预览图
                    panelSignaturePreview.setSrc(imageUrl);
                }
            }

            //执行新增操作
            function DoAdd(isContinuousNew) {
                //获得当前对象
                var me = this;

                //获得表单
                var form = me._Panel_Create.down('form');

               
                //判断表单是否有效
                if (form) {
                    //获得表单对象
                    var formBase = form.getForm();

                    //检查数据是否合法
                    if (formBase.isValid()) {
                        //提交数据
                        formBase.submit
                        (
                            {
                                url: spms.url.Action('Create', 'ActiveOperation'),
                                method: spms.constant.HttpMethod.Post,
                               // params: { Roles: postParams },
                                submitEmptyText: false,
                                waitTitle: spms.resources.text_submitting_title,
                                waitMsg: spms.resources.text_submitting,
                                success: function (panel, action) {
                                    //处理提交错误
                                    if (spms.exception.HandleSuccessError(panel, action)) {
                                        //判断是否连续新增
                                        if (isContinuousNew) {
                                            //重置表单
                                            panel.reset();

                                            //设置焦点
                                            form.down('field').focus(false, 50);
                                        }
                                        else {
                                            //启用工具栏
                                            toolbar.setDisabled(false);

                                            //返回一览标签
                                            card.getLayout().setActiveItem('spms-card-list');

                                            //刷新数据
                                            Refresh();
                                        }
                                    }
                                },
                                failure: spms.exception.HandleFailureError
                            }
                        );
                    }
                }
            }
        }
        );
    </script>
}

